package com.group56.view.userend.Log_register_module;

import com.group56.model.dao.Impl.CoachDAOImpl;
import com.group56.model.dao.Impl.CustomerDAOImpl;
import com.group56.model.entity.Coach;
import com.group56.model.entity.Customer;
import com.group56.utils.FXMLSrcMenu;
import com.group56.utils.FXMLViewHandler;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class RegisterController {
    @FXML
    private TextField user_name;
    @FXML
    private TextField password;
    @FXML
    private Button register_button;
    @FXML
    private ToggleGroup sex;
    @FXML
    private ToggleGroup identity;
    public void register() throws IOException {
        if (identity.getSelectedToggle().getUserData().equals("customer")) {
            Customer customer=new Customer();

            customer.setGoal(" ");
            customer.setAge(" ");
            customer.setGender(" ");
            customer.setHeight(" ");
            customer.setPassword(password.getText());
            SimpleDateFormat simpleDateFormat=new SimpleDateFormat();
            simpleDateFormat.applyPattern("yyyy-mm-dd HH:mm:ss a");
            Date date=new Date();
            customer.setMembershipTime(simpleDateFormat.format(date));
            customer.setSex(" ");
            customer.setWeight(" ");
            customer.setName(user_name.getText());
            CustomerDAOImpl customerDAO=new CustomerDAOImpl();
            customerDAO.insert(customer);
            System.out.println("用户注册成功");
            Stage primaryStage=(Stage)register_button.getScene().getWindow();
            primaryStage.hide();
            FXMLViewHandler.putViewInStage(primaryStage, FXMLSrcMenu.UserEnd.LOG_IN.getSrc(), "login/register");
            primaryStage.show();
        }
        if (identity.getSelectedToggle().getUserData().equals("coach")){
            Coach coach=new Coach();
            coach.setName(user_name.getText());
            coach.setSex(" ");
            coach.setPassword(password.getText());
            coach.setPicUrl("/assets/images/Coach/default.png");
            coach.setTele(" ");
            coach.setDetail(" ");
            System.out.println("教练注册成功");
            Stage primaryStage=(Stage)register_button.getScene().getWindow();
            primaryStage.hide();
            FXMLViewHandler.putViewInStage(primaryStage, FXMLSrcMenu.UserEnd.LOG_IN.getSrc(), "login/register");
            primaryStage.show();
        }
    }
}
